import { createApp } from "vue";
import App from "./App.vue";
import router from "./router";
import "./plugins/element.js";
import installElementPlus from "./plugins/element";
//添加全局样式
import "./assets/css/global.css";
//引入iconfont
import "./assets/font/iconfont.css";
// import store from "./store"
//挂载axios
import axios from "axios";
// import VueSession from 'vue-session'
// app.use(VueSession)
const app = createApp(App);
app.config.globalProperties.$http = axios;
//设置访问根路径
var base = "http://localhost:9000"
axios.defaults.baseURL = base;

installElementPlus(app);
// .use(store)
app.use(router).mount("#app");

axios.interceptors.request.use(
  (config) => {
    if (localStorage.getItem("token")) {
      config.headers.token = localStorage.getItem("token");
    }
    return config;
  },
  (error) => {
    return Promise.reject(error);
  }
);
axios.interceptors.request.use(
  (config) => {
    if (sessionStorage.getItem("role")) {
      var role = sessionStorage.getItem("role");
      config.headers["role"] = encodeURIComponent(role);
    }
    return config;
  },
  (error) => {
    return Promise.reject(error);
  }
);
